package src.list;

import java.util.Stack;

/**
 * @author starsea
 * @date 2024-08-16 10:38
 */

public class QueueByStack {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public QueueByStack () {
        stack1=new Stack<>();
        stack2=new Stack<>();

    }

    public void push(int x) {
        stack2.push(x);

    }

    public int pop() {
        if(stack1.isEmpty() && stack2.isEmpty())
        {
            return -1;
        }
        peek();
       return stack1.pop();

    }
    public int peek() {
        if(empty())
        {
            return -1;
        }
        if(stack1.isEmpty()) {
            while (!stack2.isEmpty()) {
                stack1.push(stack2.pop());
            }
        }
       return stack1.peek();


    }

    public boolean empty() {
        return stack1.isEmpty() && stack2.empty();
    }
}
